<?php

/*
 * This helper is for boolean values like active, status, publish, etc
 * also for ajax toggle
 */
class Boolean_helper{
	var $CI = null;
	public function __construct(){
        parent::__construct();
	}//endfct

	//returns yes no radio
	function yesno( $name='', $val=1 ){
		$html = '';
		$html .= 'Yes';
		$checkedYes = ($val==1) ? TRUE : FALSE;
		$html .= form_radio($name, 1, $checkedYes);
		$html .= 'No';
		$checkedNo = ($val==0) ? TRUE : FALSE;
		$html .= form_radio($name, 0, $checkedNo);
		return $html;
	}

	 function status( $val=1, $clickable=false, $dataid=null ){
	 	if(empty($dataid)) return 'undefined';
	 	if($val){
	 		if( $clickable ){
	 			return '<div id="toggle_'.$dataid.'"><a href="#" onClick="toggle(\'0\',\''.$dataid.'\');"><img src="'.base_url('assets/images/check.png').'" class="16X16_png" /></a></div>';
	 		} else {
	 			return '<img src="'.base_url('assets/images/check.png').'" class="16X16_png" />';
	 		}
	 	} else {
	 		if( $clickable ){
	 			return '<div id="toggle_'.$dataid.'"><a href="#" onClick="toggle(\'1\',\''.$dataid.'\');"><img src="'.base_url('assets/images/wrong.png').'" class="16X16_png" /></a></div>';
	 		} else {
	 			return '<img src="'.base_url('assets/images/wrong.png').'" class="16X16_png" />';
	 		}
	 	}
	 }


	 function printStatus( $val=null, $dataid=null ){
	 	if($val==1){
	 		return '<a href="#" onClick="toggle(\'0\',\''.$dataid.'\');"><img src="'.base_url('assets/images/check.png').'" class="16X16_png" /></a>';
	 	} elseif ($val == 0){
	 		return '<a href="#" onClick="toggle(\'1\',\''.$dataid.'\');"><img src="'.base_url('assets/images/wrong.png').'" class="16X16_png" /></a>';
	 	}
	 }

	 //function to call for post listing toggle
	 function ajax_status_post($val=1, $dataid=null){
	 	if(empty($dataid)) return 'undefined';
	 	$data['status'] = $val;
	 	$CI = &get_instance();
		$CI->load->model('Admin_posts_model');
		$CI->Admin_posts_model->updatePost($dataid, $data);
		return Boolean_helper::printStatus($val, $dataid);

	 }

	 function online( $val=1, $clickable=false ){
	 	if( $val ){
	 		return '<img src="'.base_url('/assets/images/online-icon.png').'" class="16x16_png" />';
	 	} else {
			return '<img src="'.base_url('/assets/images/offline-icon.png').'" class="16x16_png" />';
	 	}
	 }


}